<template>
  <div class="zhuche-box">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>注册用户</span>
        </div>
      </template>
      <div>
        <el-form>
          <el-form-item label="用户">
            <el-input v-model="user.username"
          /></el-form-item>
          <el-form-item label="密码">
            <el-input show-password v-model="user.password"
          /></el-form-item>
        </el-form>
      </div>

      <template #footer>
        <el-button type="primary" @click="zhuche">注册</el-button>
        <el-button type="primary">
          <a href="/user/login">返回登录</a></el-button>
      </template>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import { Api } from '../../script/Api';

const user = ref({
  username: '',
  password: '',
});

const zhuche = () => {
  Api.post('/user', user.value, (data) => {
    if (data.success) {
      ElMessage.success(data.message);
    } else {
      ElMessage.error(data.message);
    }
  });
};
</script>

<style scoped>
.zhuche-box {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
